package com.otaliastudios.cameraview.entity

import android.graphics.*

class WarterMarkBean(
    val tag: String = "BOOM",
    var point: Point = Point(0, 32),
    val bitmap: Bitmap? = null,
    var text: String = "",
    var color: Int = Color.WHITE,
    var textsize: Float = 32f,
    val gravity: MarkGravity = MarkGravity.DEFAULT,
    val offset: Int = 0
) {
    val paint: Paint by lazy {
        val textPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DEV_KERN_TEXT_FLAG)
        textPaint.textSize = textsize
        textPaint.color = color
        textPaint.isFakeBoldText = false
        textPaint.setShadowLayer(3f, 1f, 1f, Color.DKGRAY)
        textPaint
    }
    val textRect by lazy {
        val rect = Rect()
        paint.getTextBounds(text, 0, text.length, rect)
        rect
    }

    init {
        point.apply {
            x = when (gravity) {
                MarkGravity.CENTER -> (x - textRect.width()) / 2 + offset  //x轴居中
                MarkGravity.RIGHT -> x - textRect.width() + offset   //x轴居右
                MarkGravity.LEFT -> 0 + offset //x轴居左边
                else -> x + offset  //原始位置
            }
        }
    }


}
